<?php
/**
 * RUBIK IT Solution & Development ltd.
 *
 * PROJECT		: Rubik Ultimate
 * @version 	: 1.1
 * COPYRIGHT	: 2008
 * ------------------------------------------------------
 * 
 * [GENERAL INFO OF THIS FILE] 
 *
 * @author			hoadn <hoadn@rubik.com.vn>
 * @access			[public/private]
 * @package		 [package name]
 *
 * Created on	:Sep 19, 2008
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

RCoreImporter::cls('html.fieldInfo.AbstractHtmlFieldInfo');

class ArrayComboboxHtmlFieldInfo extends AbstractHtmlFieldInfo {

	var $_defaultValue = null;
	var $_array = null;
	var $_emptyText = '- - Select please - -';
	
	/**
	 * Constructor
	 *
	 * @param string $basicName
	 */
	function __construct($basicName, $linkRule = null) {
		parent::__construct($basicName, $linkRule);
	}
	
	/**
	 * Set Prefix for Mutilanguage
	 *
	 * @param str $prefix
	 */
	function setNamePrefix($prefix) {
		$this->_fieldName = $prefix . $this->_fieldName;
	}
	
	function setArray($array) {
		if (is_object($array)) {
			$array = RubikHelper::getProperties($array);
		}
		$this->_array = $array;
	}
	
	function setEmptyText($text=null) {
		$this->_emptyText = $text;
	}
	
	/**
	 * Function for geting the html for inputing data
	 *
	 * @abstract 
	 * @return string
	 */
	function getHtmlInputData($dataType = '', $extAttribute = '') {
		$extAttribute .= $this->buildValidateHtmlAttribute($dataType);
		return $this->createCbxFromArray( $extAttributes);
	}
	
	/**
	 * create Combobox form Array
	 *@param String$extAttributes
	 */
	function createCbxFromArray($extAttributes = ''){
		$html  = '<select name="'.$this->_fieldName.'" id="'.$this->_fieldName.'" '.$extAttributes.'>';
		if ($this->_emptyText !== false) {
			$html .= '<option value=""> '.$this->_emptyText.'</option>';
		}

		foreach($this->_array as $key=>$value){
			$sSelect = "";
			if($this->_defaultValue == $key || $this->_value == $key){
				$sSelect = "selected=\"true\"";
			}
			$html .= '<option value="'.$key.'" '.$sSelect.'>'.$value.'</option>';
		}
		
		$html .= '</select>';
		return $html;
	}
	
	/**
	 * Set the value
	 *
	 */
	function setValue($valueContain = null) {
		$this->_defaultValue = $valueContain;
		parent::setValue($valueContain);
	}
	
}
?>